package com.chaodev.base.controller;

import com.alibaba.fastjson.JSONObject;
import com.chaodev.base.dto.TrainingAddDto;
import com.chaodev.base.dto.TrainingPageDto;
import com.chaodev.base.model.Result;
import com.chaodev.base.service.TrainingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/training")
@Api(tags = "培训课程管理相关接口")
public class TrainingController {

    @Autowired
    private TrainingService trainingService;

    /**
     * 获取培训课程信息列表分页
     *
     * @param dto
     * @param request
     * @return
     */
    @ApiOperation("获取培训课程信息列表分页")
    @PostMapping("/page")
    public Result page(@RequestBody TrainingPageDto dto, HttpServletRequest request) {
        return trainingService.page(dto, request);
    }

    /**
     * 获取培训课程信息列表列表
     *
     * @param dto
     * @param request
     * @return
     */
    @ApiOperation("获取培训课程信息列表")
    @PostMapping("/list")
    public Result list(@RequestBody TrainingPageDto dto, HttpServletRequest request) {
        return trainingService.list(dto, request);
    }

    /**
     * 获取培训课程信息表对象
     *
     * @param id
     * @param request
     * @return
     */
    @ApiOperation(value = "获取培训课程信息表对象", notes = "获取培训课程信息表对象")
    @GetMapping(value = {"/getDataById/{id}"})
    public Result findById(@PathVariable Integer id, HttpServletRequest request) {
        return trainingService.findDataById(id, request);
    }

    /**
     * 保存培训课程信息
     *
     * @param dto
     * @param request
     * @return
     */
    @ApiOperation(value = "保存培训课程信息表对象", notes = "保存培训课程信息对象")
    @PostMapping(value = {"/save"})
    public Result save(@RequestBody String dto, HttpServletRequest request) {
        TrainingAddDto addDto = JSONObject.parseObject(dto, TrainingAddDto.class);
        return trainingService.saveData(addDto, request);
    }

    /**
     * 删除培训课程对象
     *
     * @param id
     * @param request
     * @return
     */
    @ApiOperation(value = "删除培训课程信息对象", notes = "删除培训课程信息表对象")
    @GetMapping(value = {"/del/{id}"})
    public Result delete(@PathVariable Integer id, HttpServletRequest request) {
        return trainingService.deleteDataById(id, request);
    }

}
